/************************************************************************************
**  
* @copyright (c) 2015-, Technology Co., LTD. All Right Reserved.
*
*************************************************************************************/
/**
* @file     duye_cap_protocol_header.cpp
* @version     
* @brief      
* @author   
* @date     2013-04-03
* @note 
*
*  1. 2018-04-03 created this file
* 
*/
#include <duye_cap_protocol_header.h>

// static const int8* DUYE_LOG_PREFIX = "duye.cap.protocol.header";

namespace duye {

LinkLayerHeader* LinkLayerHeader::createHeader(uint8* data, const uint32 dataLen) {
	IEEEHeaderStruct* header = reinterpret_cast<IEEEHeaderStruct*>(data);
	if (header->dsap == 0xaa && header->ssap == 0xaa && header->cntl == 0x03) {
		return new IEEEHeader();
	}

	return new EtherHeader();
}

NetLayerHeader* NetLayerHeader::createHeader(ProtocolType protoType) {
	switch (protoType) {
	case PROTO_IP:
		return new IpHeader();
		break;
	case PROTO_PPPOE:
		return new PppoeHeader();
		break;
	case PROTO_ARP:
		return new ArpHeader();
		break;
	case PROTO_RARP:
		return new RarpHeader();
		break;
	case PROTO_8021Q:
		return new E8021QHeader();
		break;
	default:
		break;
	}

	return NULL;
}

TfLayerHeader* TfLayerHeader::createHeader(ProtocolType protoType) {
	switch (protoType) {
	case PROTO_ICMP:
		return new ICMPHeader();
		break;
	case PROTO_IGMP:
		return new IGMPHeader();
		break;
	case PROTO_TCP:
		return new TcpHeader();
		break;
	case PROTO_UDP:
		return new UdpHeader();
		break;
	default:
		break;
	}

	return NULL;
}

}
